package com.ngkj.zmfptes.controller;

import com.alibaba.fastjson.JSONArray;
import com.ngkj.zmfptCommon.common.bean.CommonReslut;
import com.ngkj.zmfptCommon.common.bean.RentalInfo;
import com.ngkj.zmfptCommon.common.util.ResultEnum;
import com.ngkj.zmfptes.bean.RentalResponseEntity;
import com.ngkj.zmfptes.service.RentalInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author ChenHN
 * @since 2021/11/3 creation
 **/
@Slf4j
@RestController
public class RentalInfoController {

    @Resource
    private RentalInfoService rentalInfoService;


    @GetMapping("/searchRentalInfo")
    public CommonReslut<String> searchRentalInfos(RentalResponseEntity rentalInfo,
                                                                     int pageNo , int pageSize) throws IllegalAccessException, IOException, InvocationTargetException {
        try {
            Map<String,Object> map = rentalInfoService.searchRentalInfos(rentalInfo, pageNo, pageSize);
            String jsonString = JSONArray.toJSONString(map);
            return new CommonReslut<>(ResultEnum.ok, jsonString);
        } catch (Exception e) {
            e.printStackTrace();
            return new CommonReslut<>(ResultEnum.error);
        }
    }

}
